package com.liao.controller;

import com.liao.bean.Spay;
import com.liao.bean.result.Code;
import com.liao.bean.result.Msg;
import com.liao.bean.result.PageResult;
import com.liao.bean.result.Result;
import com.liao.service.SpayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class SpayController {

    @Autowired
    private SpayService spayService;

    /**
     * 根据名称模糊查询用户列表
     *
     * @param currentPage
     * @param pageSize
     * @param accountName
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/spay/querySpayListByPage")
    public PageResult<Spay> querySpayListByPage(@RequestParam(defaultValue = "1") Integer currentPage,
                                                @RequestParam(defaultValue = "5") Integer pageSize,
                                                @RequestParam(defaultValue = "") String accountName) throws Exception {
        PageResult<Spay> pageResult = spayService.querySpayListByPage(currentPage, pageSize, accountName);
        return pageResult;
    }

    /**
     * 添加
     *
     * @param payAccount
     * @param payType
     * @param accountName
     * @param operater
     * @param payMoney
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/spay/addSpay")
    public Result addSpay(String payType, String payAccount, String accountName, String operater, String payMoney) throws Exception {
        spayService.addSpay( payType,payAccount,accountName, operater, payMoney);
        return new Result(true, Code.SPAY_ADD_SUCCESS, Msg.SPAY_ADD_SUCCESS);
    }

    /**
     * 修改
     *
     * @param payId
     * @param payType
     * @param payAccount
     * @param accountName
     * @param operater
     * @param payMoney
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/spay/updateSpay")
    public Result updateSpay(Integer payId, String payType, String payAccount, String accountName, String operater, String payMoney) throws Exception {
        spayService.updateSpay(payId, payType, payAccount, accountName, operater, payMoney);
        return new Result(true, Code.SPAY_UPDATE_SUCCESS, Msg.SPAY_UPDATE_SUCCESS);
    }

    /**
     * 删除
     *
     * @param payId
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/spay/deleteSpayById")
    public Result deletePayById(String payId) throws Exception {
        spayService.deleteSpayById(payId);
        return new Result(true, Code.SPAY_DELETE_SUCCESS, Msg.SPAY_DELETE_SUCCESS);
    }

    /**
     * 批量删除
     *
     * @param payIds
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/spay/deleteSpayByIds")
    public Result deletePayByIds(@RequestParam("payIds[]") List<String> payIds) throws Exception {
        for (String payId : payIds) {
            spayService.deleteSpayById(payId);
        }
        return new Result(true, Code.SPAY_DELETE_SUCCESS, Msg.SPAY_DELETE_SUCCESS);
    }
}
